<?php
/**
 * ===============================================
 * 版权所有 2019-2050 青岛铁锤科技有限公司，并保留所有权利。
 * 网站地址: http://www.huaxianling.com
 * ===============================================
 * Author: Rag Hu
 * Created Time: 2019/7/9 14:06
 * Modified Time: 2019/7/9 14:06
 * Version: 2.0
 */

namespace App\Modules\System\Services;


use App\Modules\System\Repositories\ConfigRepository;
use App\Modules\System\Repositories\DictionaryRepository;
use Flower\Core\Repository\Eloquent\BaseService;

class ConfigService extends BaseService
{
    private $configRepository;
    private $dictionaryRepository;

    public function  __construct(ConfigRepository $configRepository,DictionaryRepository $dictionaryRepository)
    {
        $this->configRepository  = $configRepository;
        $this->dictionaryRepository  = $dictionaryRepository;
    }

    public function getConfig($keyword){
        if($this->configRepository->findByField('keyword',$keyword)->first()){
            return $this->configRepository->findByField('keyword',$keyword)->first()->val;
        }else{
            return null;
        }

    }

    public function getDictionary($code){
        if($this->dictionaryRepository->findByField('code',$code)->first()){
            return $this->dictionaryRepository->findByField('code',$code)->first()->dictionaryItem()->get()->toArray();
        }else{
            return null;
        }
    }
}